﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/TwoColumn.master" AutoEventWireup="true" CodeBehind="BookEdit.aspx.cs" Inherits="Frogism.Web.Views.Book.BookEdit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="LeftContentPlaceHolder" runat="server">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" >
     <Services>
        <asp:ServiceReference Path="~/BookService.asmx" />
    </Services>
</asp:ScriptManager>


<script language="javascript" type="text/javascript">
    function AddAuthor() {
        $("#AuthorModal").show();
    }
    function DoAdd() {
        Frogism.Web.BookService.AddAuthor($("#AuthorName").val(), OnSucceeded, OnFail, "IAuthor");
    }

    function OnFail(error) {
        alert("Unable to add Author: " + error.get_message());
    }
    function OnSucceeded(result) {
        var aid = result.Id;
        var Aname = result.Name;
        var authorList = document.getElementById("AuthorId");
        if (authorList) {
            var myOptions = document.createElement("option");
            myOptions.value = aid;
            myOptions.text = Aname;
            authorList.options[authorList.length] = myOptions;
            authorList.selectedIndex = authorList.length - 1;
        }

        $("#AuthorModal").hide();
        $("#AuthorName").val("");
    }
</script>
</form>
<div id="AuthorModal" style="display:none;position:absolute;width:300px;height:50px;background-color:White;border:solid 1px black;">
    <input type="text" id="AuthorName" name="AuthorName" value="" maxlength="200" />
    <input type="button" id="SaveAuthor" value="Add" onclick="DoAdd()" />
</div>

<div class="AuthorForm">

<form action="<%=Url.Action("BookUpdate",new {Id=ViewData.Model.Id}) %>" method="post">
<label for="AuthorId" >Author:</label><%= Html.DropDownList("AuthorId")%> <a href="#" onclick="AddAuthor()">ADD</a> <br />
<label for="Title">Title:</label><%= Html.TextBox("Title", ViewData.Model.Title, new { style = "width:300px;" })%> <br />
<label for="LastPageNumber">Pages:</label><%= Html.TextBox("LastPageNumber", ViewData.Model.LastPageNumber, new { style = "width:50px;" })%> <br />
<label for="IndexLength">Index Length:</label><%= Html.TextBox("IndexLength", ViewData.Model.IndexLength, new { style = "width:50px;" })%> <br />
<label for="Factor">Factor:</label><%= Html.TextBox("Factor", ViewData.Model.Factor, new { style = "width:50px;" })%> <br />
<label for="GoalYear">Goal Year:</label><%= Html.TextBox("GoalYear", ViewData.Model.GoalYear, new { style = "width:50px;" })%> <br />
<label for="IsPrivate">Is Private:</label><%= Html.CheckBox("IsPrivate", ViewData.Model.IsPrivate)%><br />
<label for="IsFinished">Is Finished:</label><%= Html.CheckBox("IsFinished", ViewData.Model.IsFinished)%><br />
<input type="submit" value="Save" />
</form>
</div>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="RightContentPlaceHolder" runat="server">
  <asp:ListView ID="readList" runat="server" >
		<LayoutTemplate>
			<table class="DashboardTable"  cellspacing="0" cellpadding="1">
				<tr>
					<th>Date</th>
					<th>Page</th>
					<th>Edit</th>
					<th>Delete</th>
				</tr>
				<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
				</table>
		</LayoutTemplate>
		<AlternatingItemTemplate>
			<tr>
			<td><%#((DateTime)Eval("ReadDate")).ToString("yyyy.MM.dd") %></td>
			<td class="NumberCell"><%# Eval("Page")%></td>
			<td>(<%# Html.ActionLink("Edit", "Read", new { id = Eval("Id"), bookid = ViewData.Model.Id })%>)</td>
			<td>(<a href="<%# Url.Action("ReadDelete",new { id = Eval("Id") }) %>" onclick="return confirm('Are you sure?')">X</a>)</td>
			</tr>
		</AlternatingItemTemplate>
		<ItemTemplate>
			<tr class="AltColumn">
			<td><%#((DateTime)Eval("ReadDate")).ToString("yyyy.MM.dd") %></td>
			<td class="NumberCell"><%# Eval("Page")%></td>
			<td>(<%# Html.ActionLink("Edit", "Read", new { id = Eval("Id"), bookid = ViewData.Model.Id })%>)</td>
			<td>(<a href="<%# Url.Action("ReadDelete",new { id = Eval("Id"), bookid=  ViewData.Model.Id }) %>" onclick="return confirm('Are you sure?')">X</a>)</td>
			</tr>
		</ItemTemplate>
		<EmptyDataTemplate>
			There are no reads to be listed.
		</EmptyDataTemplate>
	</asp:ListView>
</asp:Content>
